<tr><th colspan="5" id="payment_action"><%= payment.new_record? ? "New Payment" : "Update Payment" %></th></tr>
<tr>
  <td colspan="5" style="padding:0">
    <% remote_form_for :payment, payment, :url => polymorphic_path([:admin, payment]), :html => {:class => "remote_form", :id => "payment_form", :method => payment.new_record? ? :post : :put } do |payment_form| %>
      <table id="payment_form_table">
        <tr>
          <th>#</th>
          <th>Due</th>
          <th>Amount</th>
          <th>Received</th>
          <th></th>
        </tr>
        <tr>  
          <td><%= payment.id %></td>
          <td class="due"><%= payment_form.text_field :due_on, :id => "payment_due_on_date_picker", :class => "date_picker", :value => payment.due_on.blank? ? "" : payment.due_on.to_s(:numeric) %></td>
          <td class="amount"><%= payment_form.text_field :amount %></td>
          <td class="received_on"><%= payment_form.text_field :received_on, :id => "payment_received_on_date_picker", :class => "date_picker", :value => payment.received_on.blank? ? "" : payment.received_on.to_s(:numeric) %></td>
          <td class="table_buttons">
            <%= payment_form.hidden_field :project_id, :value => project.id %>
            <%= payment_form.submit (payment.new_record? ? "Add" : "Save") %>
          </td>
        </tr>
      </table>
    <% end %>    
  </td>
</tr>
  
<script type="text/javascript">
  $j( "#payment_due_on_date_picker" ).datepicker({ nextText: '&rarr;', prevText: '&larr;' });
  $j( "#payment_received_on_date_picker" ).datepicker({ nextText: '&rarr;', prevText: '&larr;' });
  
  $j("#payment_status_code").bind("change", function() {
    if(this.value == "3"){
      $j("#payment_completed_on_box").fadeIn();
    }else{
      $j("#payment_completed_on").val("");
      $j("#payment_completed_on_box").fadeOut();
    }
  });
  
</script>